package logic

import (
	"bw-renting/model/mysql"
	"bw-renting/user-rpc/internal/svc"
	"bw-renting/user-rpc/user"
	"context"
	"gorm.io/gorm"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserModifyAvatarLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserModifyAvatarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserModifyAvatarLogic {
	return &UserModifyAvatarLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Todo:修改用户头像
func (l *UserModifyAvatarLogic) UserModifyAvatar(in *user.ModifyAvatarReq) (*user.ModifyAvatarRes, error) {
	// todo: add your logic here and delete this line
	res := mysql.UserModifyAvatar(mysql.User{
		Model:     gorm.Model{ID: uint(in.UserID)},
		AvatarUrl: in.AvatarUrl,
	})
	if res.AvatarUrl != in.AvatarUrl {
		return &user.ModifyAvatarRes{
			Status: 0,
		}, nil
	}
	return &user.ModifyAvatarRes{
		Status: 1,
	}, nil
}
